package threadLearn;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadProblem implements Runnable{

	static ThreadProblem instance = new ThreadProblem();
	
	static int count = 0;
	Lock lock = new ReentrantLock();
	
	@Override
	public void run() {
		
		method();
	}
	
	private void method() {
		
		lock.lock();
		for(int i = 0; i < 100000; i++) {
			count= count+1;
		}
		lock.unlock();
		
	}

	public static void main(String[] args) {
		Thread t1 = new Thread(instance);
		Thread t2 = new Thread(instance);
		t1.start();
		t2.start();
		while(t1.isAlive() || t2.isAlive()) {
			//只要t1或t2没结束，就不执行main进程
		}
		System.out.println(count);
		System.out.println("finised...");
		
		String a = "hello world";
		byte[] bs = a.getBytes();
		for(byte b : bs) {
			System.out.println(b);
		}
		System.out.println(Runtime.getRuntime().maxMemory());
		System.out.println(Runtime.getRuntime().freeMemory());
	}

}
